package com.xzc.lease.web.app.custom.config;

import com.xzc.lease.web.app.custom.converter.StringToBaseEnumConverterFactory;
import com.xzc.lease.web.app.custom.interceptor.AuthenticationInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 徐生
 * 2024/10/13
 * description: Mvc配置类
 */
@Configuration
@Slf4j
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;
    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("注册token拦截器");
        //注册登录请求 基于token拦截器
        registry.addInterceptor(this.authenticationInterceptor).addPathPatterns("/app/**").excludePathPatterns("/app/login/**");
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        log.info("注册string转枚举类转换器");
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }
}
